package mrdemo006;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MaxMinReduce2 extends Reducer<Text,IntWritable, Text, IntWritable>{
	
	 @Override
	protected void reduce(Text k2, Iterable<IntWritable> v2s,
			Reducer<Text,IntWritable, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
		 
		 int maxNum = Integer.MIN_VALUE;
		 int minNum = Integer.MAX_VALUE;
		 
		 for(IntWritable item : v2s) {
			if(item.get() >= maxNum) {
				 maxNum = item.get();
			 }
			if(item.get() <= minNum) {
				 minNum = item.get();
			 }
		 }
		 
		 context.write(new Text("最大的数是："), new IntWritable(maxNum));
		 
		 context.write(new Text("最小的数是："), new IntWritable(minNum));
		
	 }
}
